<?php

/**
 *      [Discuz!] (C)2001-2099 Comsenz Inc.
 *      This is NOT a freeware, use is subject to license terms
 *
 *      $Id: forum.php 16805 2010-09-15 03:56:11Z zhangguosheng $
 */
error_reporting(E_ALL);
require './source/class/class_core.php';
require './source/function/function_forum.php';

$discuz = & discuz_core::instance();

//得到地区
$url = explode('.', $_SERVER['SERVER_NAME']);
if ( count($url) != 3 ){
	header("Location: http://www.ttday.com/default.php");
}else if ( count($url) == 3  && $url[0] == 'www' ){
	header("Location: http://www.ttday.com/default.php");
}
$url[0] = mysql_escape_string( $url[0] );
$short = $url[0];
list( $short ) = explode('.', $_SERVER['SERVER_NAME']);
if ( $short != 'www' && !empty( $short ) ){
	include './config/config_global.php';
	include './config/mysql.php';
	include './config/mysql_func.php';
		
	//得到本板块信息
	$sql = "SELECT * FROM `pre_common_district` as d left join `pre_f_a` as f  ON f.aid = d.id where d.level>=2 and d.`url_short` = '{$short}'";
	$rs = mysql_query($sql);
	$local_area = fetch_one( &$rs );
	if ( empty($_GET['mod']) ){
		//得到上一级板块信息
		$sql = "SELECT * FROM `pre_f_a` WHERE aid = {$local_area['upid']}";
		$rs = mysql_query($sql);
		$u_fa = fetch_all( &$rs );
		$fids= array();
		foreach ( (array)$u_fa as $d ){
			$fids[] = $d['fid'];	
		}
		$_G['tmp']['fids'] = implode(',',$fids);	
		//论坛热贴
		if ( !empty( $_G['tmp']['fids'] ) ){
			$hot_condition = $_G['tmp']['fids'] == '' ? $local_area['fid'] : $local_area['fid'].','.$_G['tmp']['fids'];
			$sql="select * from pre_forum_thread where fid in (SELECT fid FROM `pre_forum_forum` WHERE fid in ({$hot_condition}) or fup in ({$hot_condition})) and dateline > ".strtotime("-7 day")." and dateline <= ".strtotime("+1 day")."  order by views desc limit 0,7";
			$rs=mysql_query($sql);
			$hotposts = fetch_all( $rs );	
		}		
		//论坛公告
		$time = time();
		$sql = "select * from pre_forum_announcement where starttime <= $time and endtime > $time order by displayorder limit 0,7";
		$rs = mysql_query($sql);
		$announcements = fetch_all( $rs );
		//友情链接
		$sql = "select * from pre_common_friendlink where aid = {$l_area['fid']}";
		$rs = mysql_query($sql);
		$friendlinks = fetch_all( $rs );
		
		$_G['hotposts'] = $hotposts;
		$_G['announcements'] = $announcements;
		$_G['friendlinks'] = $friendlinks;
	}
	list(,$areaname) = explode(' ',$local_area['name']);
	$strlen = mb_strlen($areaname,'UTF-8');
	if ( strstr( $areaname,'上海' ) ){
		$area_display = "上海";
	}else if ( strstr( $areaname,'北京' ) ){
		$area_display = "北京";
	}else if ( strstr( $areaname,'天津' ) ){
		$area_display = "天津";
	}else if ( strstr( $areaname,'重庆' ) ){
		$area_display = "重庆";
	}else if ( strstr( $areaname,'成都' ) ){
		$area_display = "成都";
	}else if ( strstr( $areaname,'西双版纳' ) ){
		$area_display = "版纳";
	}else if ( strstr( $areaname,'呼和浩特' ) ){
		$area_display = "呼市";
	}else if ( strstr( $areaname,'大兴安岭' ) ){
		$area_display = "兴安";
	}else if ( strstr( $areaname,'齐齐哈尔' ) ){
		$area_display = "齐市";
	}else if ( strstr( $areaname,'鄂尔多斯' ) ){
		$area_display = "鄂市";
	}else if ( strstr( $areaname,'呼伦贝尔' ) ){
		$area_display = "呼伦";
	}else if ( strstr( $areaname,'乌鲁木齐' ) ){
		$area_display = "乌市";
	}else if ( strstr( $areaname,'克拉玛依' ) ){
		$area_display = "克市";
	}else if ( strstr( $areaname,'图木舒克' ) ){
		$area_display = "图市";
	}else if ( strstr( $areaname,'巴音郭楞' ) ){
		$area_display = "巴州";
	}else if ( strstr( $areaname,'博尔塔拉' ) ){
		$area_display = "博州";
	}else if ( strstr( $areaname,'克孜勒苏' ) ){
		$area_display = "克州";
	}else {
		$area_display = $areaname;
	}
	$_G['local_area'] = $local_area;
	$_G['area_display'] = $area_display;	
}else{
	$area_display = '';
}
define('APPTYPEID', 2);
define('CURSCRIPT', 'forum');

$modarray = array('ajax','announcement','attachment','forumdisplay',
	'group','image','index','medal','misc','modcp','notice','post','redirect',
	'relatekw','relatethread','rss','topicadmin','trade','viewthread'
);

$modcachelist = array(
	'index'		=> array('announcements', 'onlinelist', 'forumlinks', 'advs_index',
			'heats', 'historyposts', 'onlinerecord', 'userstats'),
	'forumdisplay'	=> array('smilies', 'announcements_forum', 'globalstick', 'forums',
			'icons', 'onlinelist', 'forumstick','threadtable_info', 'threadtableids', 'stamps'),
	'viewthread'	=> array('smilies', 'smileytypes', 'forums', 'usergroups', 'ranks',
			'stamps', 'bbcodes', 'smilies',	'custominfo', 'groupicon', 'stamps',
			'threadtableids', 'threadtable_info'),
	'post'		=> array('bbcodes_display', 'bbcodes', 'smileycodes', 'smilies', 'smileytypes',
			'icons', 'domainwhitelist'),
	'space'		=> array('fields_required', 'fields_optional', 'custominfo'),
	'group'		=> array('grouptype'),
);

$mod = !in_array($discuz->var['mod'], $modarray) ? 'index' : $discuz->var['mod'];

define('CURMODULE', $mod != 'redirect' ? $mod : 'viewthread');
$cachelist = array();
if(isset($modcachelist[CURMODULE])) {
	$cachelist = $modcachelist[CURMODULE];
}
if($discuz->var['mod'] == 'group') {
	$_G['basescript'] = 'group';
}
$discuz->cachelist = $cachelist;
$discuz->init();

loadforum();
set_rssauth();
runhooks();


$navtitle = str_replace('{bbname}', $_G['setting']['bbname'], $_G['setting']['seotitle']['forum']);

require DISCUZ_ROOT.'./source/module/forum/forum_'.$mod.'.php';

?>